import { setToken, getToken, removesToken } from '@/utils/storage'
// 获取用户信息 ajax请求
import { getUserInfo } from '@/api/user'
const state = {
  token: getToken(),
  userInfo: {}
}
const mutations = {
  setToken(state, value) {
    state.token = value
    setToken(value)
  },
  removeToken(state) {
    // 清除token
    state.token = {}
    // 清除本地存储的token
    removesToken()
  },
  // 存储个人中心的数据
  setUserInfo(state, obj) {
    state.userInfo = obj
  }
}
const actions = {
  // 获取用户信息
  async AsyncGetUserInfo(context) {
    const res = await getUserInfo()
    context.commit('setUserInfo', res.data)
  }
}
const getters = {}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
